package com.epro.dx.task;

import java.util.ArrayList;

import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.epro.dx.util.ActivityUtil;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.facade.model.NoticeGroupsModel;
import android.content.Context;

/************************
 * @author Tony
 * @Date:2016-5-3上午11:25:19
 * @描述:获取最新的消息
 ************************/
public class GetNoticeTypeListAsyncTask extends BaseNeedReLoginTask {

    private MyAsyncTaskListenner myAsyncTaskListenner;
    private ArrayList<NoticeGroupsModel> noticeTypeList;
    private Context mContext;

    public GetNoticeTypeListAsyncTask(Context mContext, MyAsyncTaskListenner myAsyncTaskListenner) {
        this.mContext = mContext;
        this.myAsyncTaskListenner = myAsyncTaskListenner;

    }

    @Override
    protected void onPreExecute() {
        if (null != myAsyncTaskListenner) {
            myAsyncTaskListenner.onPreTask();
        }
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(Void... params) {
        try {
            noticeTypeList = ProviderFactory.createMessageService().getNoticeTypeList(ActivityUtil.getCustomerID(), ActivityUtil.getCustomerToken());
        } catch (DxException e) {
            return e.getErrCode();
        }
        return "0";
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        if (null != myAsyncTaskListenner && !isRelogin) {
            myAsyncTaskListenner.onPostTask(result, noticeTypeList);
        }
    }

    @Override
    protected Context setContext() {
        return mContext;
    }

    @Override
    protected BaseNeedReLoginTask setTask() {
        return new GetNoticeTypeListAsyncTask(mContext, myAsyncTaskListenner);
    }

}
